package com.ruoyi.service.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.service.domain.ServiceUsers;
import com.ruoyi.service.service.IServiceUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户账号表Controller
 * 
 * @author ZDL
 * @date 2024-11-19
 */
@RestController
@Api(tags = "APP端用户管理")
@RequestMapping("/service/users")
public class ServiceUsersController extends BaseController
{
    @Autowired
    private IServiceUsersService serviceUsersService;

    /**
     * 查询用户账号表列表
     */
    @ApiOperation("获取用户列表")
    @PreAuthorize("@ss.hasPermi('service:users:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceUsers serviceUsers)
    {
        startPage();
        List<ServiceUsers> list = serviceUsersService.selectServiceUsersList(serviceUsers);
        return getDataTable(list);
    }

    /**
     * 导出用户账号表列表
     */
    @PreAuthorize("@ss.hasPermi('service:users:export')")
    @Log(title = "用户账号表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceUsers serviceUsers)
    {
        List<ServiceUsers> list = serviceUsersService.selectServiceUsersList(serviceUsers);
        ExcelUtil<ServiceUsers> util = new ExcelUtil<ServiceUsers>(ServiceUsers.class);
        util.exportExcel(response, list, "用户账号表数据");
    }

    /**
     * 获取用户账号表详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:users:query')")
    @GetMapping(value = "/{usersId}")
    public AjaxResult getInfo(@PathVariable("usersId") Long usersId)
    {
        return success(serviceUsersService.selectServiceUsersByUsersId(usersId));
    }

    /**
     * 新增用户账号表
     */
    @PreAuthorize("@ss.hasPermi('service:users:add')")
    @Log(title = "用户账号表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceUsers serviceUsers)
    {
        return toAjax(serviceUsersService.insertServiceUsers(serviceUsers));
    }

    /**
     * 修改用户账号表
     */
    @PreAuthorize("@ss.hasPermi('service:users:edit')")
    @Log(title = "用户账号表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceUsers serviceUsers)
    {
        return toAjax(serviceUsersService.updateServiceUsers(serviceUsers));
    }

    /**
     * 删除用户账号表
     */
    @PreAuthorize("@ss.hasPermi('service:users:remove')")
    @Log(title = "用户账号表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{usersIds}")
    public AjaxResult remove(@PathVariable Long[] usersIds)
    {
        return toAjax(serviceUsersService.deleteServiceUsersByUsersIds(usersIds));
    }
}
